package logic

import (
	"context"
	"hotel/hotelrpc/hotelrpc"
	"hotel/pkg"
	"strconv"

	"hotel/api/internal/svc"
	"hotel/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HotelUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHotelUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HotelUpdateLogic {
	return &HotelUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HotelUpdateLogic) HotelUpdate(req *types.HotelUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.HotelRpc.HotelUpdate(l.ctx, &hotelrpc.HotelUpdateRequest{
		Img:       req.Img,
		VipName:   req.VipName,
		Sex:       req.Sex,
		NickName:  req.NickName,
		Signature: req.Signature,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    "500",
		}, nil
	}
	handler, err := pkg.TokenHandler(strconv.FormatInt(update.Id, 10))
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    "500",
		}, nil
	}

	return &types.Response{
		Message: "完善成功",
		Data:    handler,
		Code:    "200",
	}, nil
}
